// pages/10_learn_api/index.js
Page({
  // 1.弹窗相关的API
  onShowToast() {
    wx.showToast({
      title: "show-toast-name",
      icon: "error",
      duration: 5000,
      mask: true,
      success: (res) => {
        console.log("res: ", res);
      },
      fail: (err) => {
        console.log("err: ", err);
      }
    })
  },
  onShowModal() {
    wx.showModal({
      title: "show-modal-name",
      content: "use show modal content",
      confirmColor: "#f00",
      cancelColor: "#0f0",
      success: (res) => {
        if (res.cancel) {
          console.log("用户点击取消");
        } else if (res.confirm) {
          console.log("用户点击了确定");
        }
      }
    })
  },
  onShowAction() {
    wx.showActionSheet({
      itemList: ['衣服', '裤子', '鞋子'],
      success(res) {
        console.log(res.tapIndex);
      },
      fail(err) {
        console.log("err: ", err);
      }
    })
  },

  // 2.分享功能
  onShareAppMessage() {
    return {
      title: "旅途的内容",
      path: "/pages/favor/favor",
      imageUrl: "/assets/nhlt.jpg"
    }
  },
  // 3.获取用户的设备信息
  onGetSystemInfo() {
    // 1.获取手机的基本信息
    wx.getSystemInfo({
      success: (res) => {
        console.log("获取手机的基本信息", res);
      }
    })

    // 2. 获取当前的位置信息
    wx.getLocation({
      success: (res) => {
        console.log("获取当前的位置信息: ", res);
      }
    })
  },

  // 4.本地存储方式
  onLocalStorage() {
    // 1. 存储一些键值对
    wx.setStorageSync("name", "storage-sync-name")

    // 2. 获取storage中内容
    const name = wx.getStorageSync('name')
    console.log(name);

    // 3. 删除storage中内容
    wx.removeStorageSync('name')

    // 4. 清空stroage内容
    wx.clearStorage()

    // 异步操作
    wx.setStorage({
      key: "books",
      data: "storage-name",
      encrypt: true,
      success: (res) => {
        wx.getStorage({
          key: "books",
          encrypt: true,
          success: (res) => {
            console.log(res);
          }
        })
      }
    })
  }
})